<template>
	<view>
		<view class="friend-apply-pop-mask" v-show="maskShow"></view>
		<friend-apply-content v-for="(item,index) in applyDataList" :key="item.id" :applyData="item" @confirm="confirm" @cancel="cancel" @close="cleanApplyDataList"></friend-apply-content>
	</view>
</template>

<script>
	import friendApplyContent from './friendApplyContent.vue'
	export default {
		components:{
			friendApplyContent
		},
		data() {
			return {
				applyDataList:[]
			}
		},
		computed:{
			maskShow(){
				return this.applyDataList.length > 0
			}
		},
		mounted() {
			
		},
		methods: {
			show(data){
				data.id = +new Date()
				this.applyDataList.push(data)
				// this.applyDataList = [data] // 只同时存在一条的情况
				
				if(!this.cbs){
					this.cbs = {}
				}
				this.cbs[data.id] = {
					confirmCb: data.confirmCb,
					cancelCb: data.cancelCb
				}
				
			},
			cleanApplyDataList(id){
				this.applyDataList = this.applyDataList.filter(item => {
					return item.id !== id
				})
			},
			hide(){
				this.applyDataList = []
			},
			confirm(id){
				const cbObj = this.cbs[id]
				if(cbObj){
					if(cbObj.confirmCb){
						cbObj.confirmCb()
					}
				}
			},
			cancel(id){
				const cbObj = this.cbs[id]
				if(cbObj){
					if(cbObj.cancelCb){
						cbObj.cancelCb()
					}
				}
			}
		}
	}
</script>


<style lang="less" scoped>
	.friend-apply-pop-mask {
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		background-color: rgba(0, 0, 0, 0.3);
		z-index: 99;
		animation: fadeIn 0.3s forwards;
	}
	
	@keyframes fadeIn {
		0% {
			opacity: 0;
		}
	
		100% {
			opacity: 1;
		}
	}
	
</style>
